<!---
  Teleport 会更好的实现
  1. Vux -> toast/alert/Confim
  2. Vue-plugin-rxdialog
  - - - -
  都是 在 body 内部最后的位置
-->

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Teleport - vue3-js</title>
  <script src="../../js/vue.js"></script>
  <style>
    .modal {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: rgba(0, 0, 0, .5);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    .modal div {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background-color: white;
      width: 300px;
      height: 300px;
      padding: 5px;
    }
  </style>
</head>

<body>
  <div id="app" style="position: relative;">
    <h3>Tooltips with Vue 3 Teleport</h3>
    <div>
      <modal-button></modal-button>
    </div>
  </div>

  <script>
    const app = Vue.createApp({});

    app.component('modal-button', {
      template: `
        <button @click="modalOpen = true">
            Open full screen modal! (With teleport!)
        </button>

        <teleport to="body">
         <!-- 可以 试试 v-show -->
          <div v-if="modalOpen" class="modal">
            <div>
              I'm a teleported modal!
              (My parent is "body")
              <button @click="modalOpen = false">
                Close
              </button>
            </div>
          </div>
        </teleport>
      `,
      data() {
        return {
          modalOpen: false
        }
      }
    })

    app.mount('#app')
  </script>
</body>

</html>